library(tidyverse)
library(showtext)
library(magrittr)
library(estimatr)
library(metafor)
library(broom)
library(ggbeeswarm)

covariates <-
  "+ lucid_pid_7n +
  lucid_age +
  lucid_race +
  lucid_hhin +
  political_knowledge_pre +
  political_interest_pre +
  cognitive_reflection_pre +
  need_for_cognition_pre +
  extraversion_pre +
  agreeableness_pre +
  conscientiousness_pre +
  emotional_stability_pre +
  openness_to_experience_pre"


covariates_no_pid <-
  "lucid_age +
  lucid_race +
  lucid_hhin +
  political_knowledge_pre +
  political_interest_pre +
  cognitive_reflection_pre +
  need_for_cognition_pre +
  extraversion_pre +
  agreeableness_pre +
  conscientiousness_pre +
  emotional_stability_pre +
  openness_to_experience_pre"


all_panels_long <- "https://github.com/thomasjwood/cgptw22/raw/main/all_panels_long.rds" %>% 
  url %>% 
  gzcon %>% 
  readRDS

treatments_df <- "https://github.com/thomasjwood/cgptw22/raw/main/treatments_df.rds" %>% 
  url %>% 
  gzcon %>% 
  readRDS

persistence_p2_df <-
  all_panels_long %>%
  filter(!is.na(outcome_w1),
         !is.na(outcome_w2),
         treatment != "misinformation")

persistence_p3_df <-
  all_panels_long %>%
  filter(!is.na(outcome_w1),
         !is.na(outcome_w3),
         treatment != "misinformation")


filter_and_flip <- function(data) {
  data %>%
    filter(term %in% c("treatmentcontrol", "treatmentfactcheck")) %>%
    mutate(
      estimate = if_else(term == "treatmentcontrol",-1 * estimate, estimate),
      conf.low = if_else(term == "treatmentcontrol",-1 * conf.low, conf.low),
      conf.high = if_else(term == "treatmentcontrol",-1 * conf.high, conf.high),
    )
  
}



# Average Treatment Effects at Wave 1 -------------------------------------

ates_w1_all_noadj <-
  all_panels_long %>%
  group_by(fc, panel, panel_factor, rating) %>%
  do(tidy(lm_robust(formula(
    outcome_w1 ~ treatment
  ), data = .))) %>%
  filter_and_flip

ates_w1_all_adj <-
  all_panels_long %>%
  group_by(fc, panel, panel_factor, rating) %>%
  do(tidy(lm_robust(formula(
    paste0("outcome_w1 ~ treatment +", covariates)
  ), data = .))) %>%
  filter_and_flip


ates_w1_all_adj %>%
  mutate(term2 = term) %>%
  group_by(term2) %>%
  do(tidy(rma.uni(estimate, sei = std.error, data = .), conf.int = TRUE))


ates_w1_all_adj %>%
  mutate(term2 = term) %>%
  group_by(term2, rating) %>%
  do(tidy(rma.uni(estimate, sei = std.error, data = .), conf.int = TRUE)) %>%
  ggplot() +
  aes(estimate, rating) +
  geom_point() +
  geom_linerange(aes(xmin = conf.low, xmax = conf.high)) +
  facet_grid(~term2)


# Cates -----------------------------------------------------

cates_w1_all_noadj <-
  all_panels_long %>%
  filter(lucid_pid_3 != "Independent") %>%
  group_by(fc, panel, panel_factor, lucid_pid_3) %>%
  do(tidy(lm_robust(formula(
    outcome_w1 ~ treatment
  ), data = .))) %>%
  filter_and_flip


cates_w1_all_adj <-
  all_panels_long %>%
  filter(lucid_pid_3 != "Independent") %>%
  group_by(fc, panel, panel_factor, lucid_pid_3) %>%
  do(tidy(lm_robust(formula(
    paste0("outcome_w1 ~ treatment +", covariates)
  ), data = .))) %>%
  filter_and_flip

diff_in_cates_w1_all_adj <-
  all_panels_long %>%
  filter(lucid_pid_3 != "Independent") %>%
  group_by(fc, panel, topic_short_2) %>%
  do(tidy(lm_robust(formula(
    paste0("outcome_w1 ~ treatment + lucid_pid_3 + lucid_pid_3*treatment + lucid_pid_3*(", covariates, ")")
  ), data = .))) %>% 
  filter(
    term %in% 
      c("treatmentcontrol:lucid_pid_3Republican",
        "treatmentfactcheck:lucid_pid_3Republican")
  ) %>% 
  ungroup



trait_cates_w1_all_noadj <-
  all_panels_long %>%
  pivot_longer(
    cols = c(
      grp_crt,
      grp_polint,
      grp_nfc,
      grp_openness,
      grp_conscientiousness,
      grp_extraversion,
      grp_agree,
      grp_emotstab,
      grp_pk
    )
  ) %>%
  filter(!is.na(value), value != "med") %>%
  group_by(name, value,fc, panel, panel_factor) %>%
  do(tidy(lm_robust(formula(
    outcome_w1 ~ treatment
  ), data = .))) %>%
  filter_and_flip


trait_cates_w1_all_adj <-
  all_panels_long %>%
  pivot_longer(
    cols = c(
      grp_crt,
      grp_polint,
      grp_nfc,
      grp_openness,
      grp_conscientiousness,
      grp_extraversion,
      grp_agree,
      grp_emotstab,
      grp_pk
    )
  ) %>%
  filter(!is.na(value), value != "med") %>%
  group_by(name, value, fc, panel, panel_factor) %>%
  do(tidy(lm_robust(formula(
    paste0("outcome_w1 ~ treatment +", covariates)
  ), data = .))) %>%
  filter_and_flip %>%
  mutate(type2 = term)


meta_trait_cates_w1_all_adj <-
  trait_cates_w1_all_adj %>% 
  group_by(name, value, type2) %>%
  do(tidy(rma.uni(
    yi = estimate, sei = std.error, data = .
  ), conf.int = TRUE)) 




meta_trait_dic_w1_all_adj <-
  trait_cates_w1_all_adj %>% 
  group_by(name, type2) %>%
  do(tidy(rma.uni(
    yi = estimate, sei = std.error, mods = value, data = .
  ), conf.int = TRUE)) %>%
  filter(term == "mods")


# Trait persistence


trait_cates_w2_p2_adj <-
  persistence_p2_df %>%
  pivot_longer(
    cols = c(
      grp_crt,
      grp_polint,
      grp_nfc,
      grp_openness,
      grp_conscientiousness,
      grp_extraversion,
      grp_agree,
      grp_emotstab,
      grp_pk
    )
  ) %>%
  filter(!is.na(value), value != "med") %>%
  group_by(name, value, fc, panel, panel_factor) %>%
  do(tidy(lm_robust(formula(
    paste0("outcome_w2 ~ treatment +", covariates)
  ), data = .))) %>%
  filter_and_flip %>%
  mutate(type2 = term)



ggplot(trait_cates_w2_p2_adj, 
       aes(estimate, name, group = value, color = value)) +
  geom_point()

meta_trait_cates_w2_p2_adj <- 
  trait_cates_w2_p2_adj  %>% 
  group_by(name, value, type2) %>%
  do(tidy(rma.uni(
    yi = estimate, sei = std.error, data = .
  ), conf.int = TRUE)) 


# w1 to w2 persistence ----------------------------------------------------


ates_w1_p2_noadj <-
  persistence_p2_df %>%
  group_by(fc, panel, panel_factor) %>%
  do(tidy(lm_robust(formula(
    outcome_w1 ~ treatment
  ), data = .))) %>%
  filter_and_flip

ates_w2_p2_noadj <-
  persistence_p2_df %>%
  group_by(fc, panel, panel_factor) %>%
  do(tidy(lm_robust(formula(
    outcome_w2 ~ treatment
  ), data = .))) %>%
  filter_and_flip

iv_p2_noadj <-
  persistence_p2_df %>%
  group_by(fc, panel, panel_factor) %>%
  do(tidy(iv_robust(
    formula(outcome_w2 ~ outcome_w1 | treatment), data = .
  ))) %>% 
  filter(term == "outcome_w1")

ates_w1_p2_adj <-
  persistence_p2_df %>%
  group_by(fc, panel, panel_factor) %>%
  do(tidy(lm_robust(formula(
    paste0("outcome_w1 ~ treatment +", covariates)
  ), data = .))) %>%
  filter_and_flip

ates_w2_p2_adj <-
  persistence_p2_df %>%
  group_by(fc, panel, panel_factor) %>%
  do(tidy(lm_robust(formula(
    paste0("outcome_w2 ~ treatment +", covariates)
  ), data = .))) %>%
  filter_and_flip


iv_p2_adj <-
  persistence_p2_df %>%
  group_by(fc, panel, panel_factor) %>%
  do(tidy(iv_robust(formula(
    paste0(
      "outcome_w2 ~ outcome_w1 +",
      covariates,
      "|  treatment +",
      covariates
    )
  )
  , data = .))) %>% 
  filter(term == "outcome_w1")

# w1 to w3 persistence

ates_w1_p3_noadj <-
  persistence_p3_df %>%
  group_by(fc, panel, panel_factor) %>%
  do(tidy(lm_robust(formula(
    outcome_w1 ~ treatment
  ), data = .))) %>%
  filter_and_flip

ates_w2_p3_noadj <-
  persistence_p3_df %>%
  group_by(fc, panel, panel_factor) %>%
  do(tidy(lm_robust(formula(
    outcome_w2 ~ treatment
  ), data = .))) %>%
  filter_and_flip

ates_w3_p3_noadj <-
  persistence_p3_df %>%
  group_by(fc, panel, panel_factor) %>%
  do(tidy(lm_robust(formula(
    outcome_w3 ~ treatment
  ), data = .))) %>%
  filter_and_flip

iv_p3_noadj <-
  persistence_p3_df %>%
  group_by(fc, panel, panel_factor) %>%
  do(tidy(iv_robust(
    formula(outcome_w3 ~ outcome_w1 | treatment), data = .
  ))) %>% 
  filter(term == "outcome_w1")


ates_w1_p3_adj <-
  persistence_p3_df %>%
  group_by(fc, panel, panel_factor) %>%
  do(tidy(lm_robust(formula(
    paste0("outcome_w3 ~ treatment +", covariates)
  ), data = .))) %>%
  filter_and_flip

ates_w2_p3_adj <-
  persistence_p3_df %>%
  group_by(fc, panel, panel_factor) %>%
  do(tidy(lm_robust(formula(
    paste0("outcome_w3 ~ treatment +", covariates)
  ), data = .))) %>%
  filter_and_flip


ates_w3_p3_adj <-
  persistence_p3_df %>%
  group_by(fc, panel, panel_factor) %>%
  do(tidy(lm_robust(formula(
    paste0("outcome_w2 ~ treatment +", covariates)
  ), data = .))) %>%
  filter_and_flip


iv_p3_adj <-
  persistence_p3_df %>%
  group_by(fc, panel, panel_factor) %>%
  do(tidy(iv_robust(formula(
    paste0(
      "outcome_w2 ~ outcome_w1 +",
      covariates,
      "|  treatment +",
      covariates
    )
  )
  , data = .))) %>% 
  filter(term == "outcome_w1")


# removing race?
covariates <-
  "+ lucid_pid_7n +
  lucid_age +
  lucid_hhin +
  political_knowledge_pre +
  political_interest_pre +
  cognitive_reflection_pre +
  need_for_cognition_pre +
  extraversion_pre +
  agreeableness_pre +
  conscientiousness_pre +
  emotional_stability_pre +
  openness_to_experience_pre"



cates_w1_p2_adj <-
  persistence_p2_df %>%
  filter(lucid_pid_3 != "Independent") %>%
  group_by(fc, panel, panel_factor, lucid_pid_3) %>%
  do(tidy(lm_robust(formula(
    paste0("outcome_w1 ~ treatment +", covariates)
  ), data = .))) %>%
  filter_and_flip

cates_w2_p2_adj <-
  persistence_p2_df %>%
  filter(lucid_pid_3 != "Independent") %>%
  group_by(fc, panel, panel_factor, lucid_pid_3) %>%
  do(tidy(lm_robust(formula(
    paste0("outcome_w2 ~ treatment +", covariates)
  ), data = .))) %>%
  filter_and_flip


cates_w1_p3_adj <-
  persistence_p3_df %>%
  filter(lucid_pid_3 != "Independent") %>%
  group_by(fc, panel, panel_factor, lucid_pid_3) %>%
  do(tidy(lm_robust(formula(
    paste0("outcome_w1 ~ treatment +", covariates)
  ), data = .))) %>%
  filter_and_flip

cates_w2_p3_adj <-
  persistence_p3_df %>%
  filter(lucid_pid_3 != "Independent") %>%
  group_by(fc, panel, panel_factor, lucid_pid_3) %>%
  do(tidy(lm_robust(formula(
    paste0("outcome_w2 ~ treatment +", covariates)
  ), data = .))) %>%
  filter_and_flip

cates_w3_p3_adj <-
  persistence_p3_df %>%
  filter(lucid_pid_3 != "Independent") %>%
  group_by(fc, panel, panel_factor, lucid_pid_3) %>%
  do(tidy(lm_robust(formula(
    paste0("outcome_w3 ~ treatment +", covariates)
  ), data = .))) %>%
  filter_and_flip



meta_ates_w1_p2_adj <-
  ates_w1_p2_adj %>%
  left_join(treatments_df, by = c("fc", "panel")) %>%
  group_by(congeniality) %>%
  do(tidy(rma.uni(
    yi = estimate, sei = std.error, data = .
  ), conf.int = TRUE)) %>%
  mutate(wave = 1,
         issues = "All Issues",
         lucid_pid_3 = "All Subjects")

meta_ates_w2_p2_adj <-
  ates_w2_p2_adj %>%
  left_join(treatments_df, by = c("fc", "panel")) %>%
  group_by(congeniality) %>%
  do(tidy(rma.uni(
    yi = estimate, sei = std.error, data = .
  ), conf.int = TRUE)) %>%
  mutate(wave = 2,
         issues = "All Issues",
         lucid_pid_3 = "All Subjects")


meta_ates_w1_p3_adj <-
  ates_w1_p3_adj %>%
  left_join(treatments_df, by = c("fc", "panel")) %>%
  group_by(congeniality) %>%
  do(tidy(rma.uni(
    yi = estimate, sei = std.error, data = .
  ), conf.int = TRUE)) %>%
  mutate(wave = 1, issues = "Issues across three waves", lucid_pid_3 = "All Subjects")

meta_ates_w2_p3_adj <-
  ates_w2_p3_adj %>%
  left_join(treatments_df, by = c("fc", "panel")) %>%
  group_by(congeniality) %>%
  do(tidy(rma.uni(
    yi = estimate, sei = std.error, data = .
  ), conf.int = TRUE)) %>%
  mutate(wave = 2, issues = "Issues across three waves", lucid_pid_3 = "All Subjects")

meta_ates_w3_p3_adj <-
  ates_w3_p3_adj %>%
  left_join(treatments_df, by = c("fc", "panel")) %>%
  group_by(congeniality) %>%
  do(tidy(rma.uni(
    yi = estimate, sei = std.error, data = .
  ), conf.int = TRUE)) %>%
  mutate(wave = 3, issues = "Issues across three waves", lucid_pid_3 = "All Subjects")


meta_cates_w1_p2_adj <-
  cates_w1_p2_adj %>%
  left_join(treatments_df, by = c("fc", "panel")) %>%
  group_by(lucid_pid_3, congeniality) %>%
  do(tidy(rma.uni(
    yi = estimate, sei = std.error, data = .
  ), conf.int = TRUE)) %>%
  mutate(wave = 1, issues = "All Issues")

meta_cates_w2_p2_adj <-
  cates_w2_p2_adj %>%
  left_join(treatments_df, by = c("fc", "panel")) %>%
  group_by(lucid_pid_3, congeniality) %>%
  do(tidy(rma.uni(
    yi = estimate, sei = std.error, data = .
  ), conf.int = TRUE)) %>%
  mutate(wave = 2, issues = "All Issues")


meta_cates_w1_p3_adj <-
  cates_w1_p3_adj %>%
  left_join(treatments_df, by = c("fc", "panel")) %>%
  group_by(lucid_pid_3, congeniality) %>%
  do(tidy(rma.uni(
    yi = estimate, sei = std.error, data = .
  ), conf.int = TRUE)) %>%
  mutate(wave = 1, issues = "Issues across three waves")

meta_cates_w2_p3_adj <-
  cates_w2_p3_adj %>%
  left_join(treatments_df, by = c("fc", "panel")) %>%
  group_by(lucid_pid_3, congeniality) %>%
  do(tidy(rma.uni(
    yi = estimate, sei = std.error, data = .
  ), conf.int = TRUE)) %>%
  mutate(wave = 2, issues = "Issues across three waves")

meta_cates_w3_p3_adj <-
  cates_w3_p3_adj %>%
  left_join(treatments_df, by = c("fc", "panel")) %>%
  group_by(lucid_pid_3, congeniality) %>%
  do(tidy(rma.uni(
    yi = estimate, sei = std.error, data = .
  ), conf.int = TRUE)) %>%
  mutate(wave = 3, issues = "Issues across three waves")


persistence_meta <-
  bind_rows(
    meta_ates_w1_p2_adj,
    meta_ates_w2_p2_adj,
    meta_ates_w1_p3_adj,
    meta_ates_w2_p3_adj,
    meta_ates_w3_p3_adj,
    meta_cates_w1_p2_adj,
    meta_cates_w2_p2_adj,
    meta_cates_w1_p3_adj,
    meta_cates_w2_p3_adj,
    meta_cates_w3_p3_adj
  )


# Thermometers ----------------------------------------------


ft_long <- 
  all_panels_long %>%
  pivot_longer(cols = starts_with("w1_ft"), names_to = "target", values_to = "thermometer") %>% 
  filter(!is.na(thermometer))

ft_ates_w1_all_adj <-
  ft_long %>% 
  filter(
    !is.na(lucid_pid_3)
  ) %>% 
  group_by(fc, panel, panel_factor, target, lucid_pid_3) %>%
  do(tidy(lm_robust(formula(
    paste0("thermometer ~ treatment +", covariates_no_pid)
  ), data = .))) %>% 
  filter_and_flip


meta_ft_ates <- ft_ates_w1_all_adj %>%
  rename(ty2 = term) %>% 
  group_by(lucid_pid_3, target, ty2) %>%
  do(tidy(rma.uni(
    yi = estimate, sei = std.error, data = .
  ), conf.int = TRUE)) 

t0 <- meta_trait_cates_w1_all_adj
t1 <- trait_cates_w1_all_adj
t2 <- meta_trait_dic_w1_all_adj

grp_frm <- c(
  "grp_polint",
  "grp_pk",
  "grp_crt",
  "grp_nfc",
  
  "grp_emotstab", 
  "grp_extraversion",
  "grp_agree",
  "grp_conscientiousness",
  "grp_openness"
)

grp_to <- c(
  "Political interest",
  "Political knowledge",
  "Cognitive Reflection Test",
  "Need for Cognition",
  
  "Personality - Emotional Stability",
  "Personality - Extraversion",
  "Personality - Agreeableness",
  "Personality - Conscientiousness",
  "Personality - Openness"
  )



t0$name %<>%
  plyr::mapvalues(grp_frm, grp_to) %>% 
  factor(grp_to)
t1$name %<>%
  plyr::mapvalues(grp_frm, grp_to) %>% 
  factor(grp_to)
t2$name %<>%
  plyr::mapvalues(grp_frm, grp_to) %>% 
  factor(grp_to)


t2$rfac <- t2$name  %>% 
  str_detect("Personality") %>% 
  ifelse(
    "Personality\ntraits",
    "Other\nheterogeneity\ndimensions"
  ) %>% 
  factor(
    c("Personality\ntraits",
      "Other\nheterogeneity\ndimensions")
  )

t1$rfac <- t1$name %>% 
  str_detect("Personality") %>% 
  ifelse(
    "Personality\ntraits",
    "Other\nheterogeneity\ndimensions"
    ) %>% 
  factor(
    c("Personality\ntraits",
      "Other\nheterogeneity\ndimensions")
    )

t0$rfac <- t0$name %>% 
  str_detect("Personality") %>% 
  ifelse(
    "Personality\ntraits",
    "Other\nheterogeneity\ndimensions"
  ) %>% 
  factor(
    c("Personality\ntraits",
      "Other\nheterogeneity\ndimensions")
  )

t0$cfac <- t0$type2 %>% 
  str_detect("control") %>% 
  ifelse(
    "Misinformation effects",
    "Correction effects"
  ) %>% 
  factor(
    c("Misinformation effects",
      "Correction effects")
  )

t1$cfac <- t1$term %>% 
  str_detect("control") %>% 
  ifelse(
    "Misinformation effects",
    "Correction effects"
  ) %>% 
  factor(
    c("Misinformation effects",
      "Correction effects")
    )


t2$cfac <- t2$term %>% 
  str_detect("control") %>% 
  ifelse(
    "Misinformation effects",
    "Correction effects"
  ) %>% 
  factor(
    c("Misinformation effects",
      "Correction effects")
  )

t0$yint <- t0$rfac %>% 
  equals(
    "Personality\ntraits"
  ) %>% 
  ifelse(-4, 0)

t1$yint <- t1$rfac %>% 
  equals(
    "Personality\ntraits"
  ) %>% 
  ifelse(-4, 0)

t2$yint <- t2$rfac %>%
  equals(
    "Personality\ntraits"
  ) %>%
  ifelse(-4, 0)

t2 %<>% 
  filter(
    p.value < .05
  ) %>% 
  # join the low value
  left_join(
    t0 %>%
      group_by(name, type2, rfac, cfac) %>% 
      summarize(
        xlo = estimate %>% min,
        xhi = estimate %>% max
        )
    ) %>% 
  ungroup %>% 
  mutate(
    mid = xhi %>% 
      add(xlo) %>% 
      divide_by(2),
    slab = c(
      "***", "**", "*", ""
      ) %>% 
      extract(
        p.value %>% 
          findInterval(
            c(-Inf, .001, .01, .05, Inf)
          )
      )
    )

t1 %>% 
  ggplot() +
  geom_vline(
    aes(
      xintercept = 0,
    ),
    linetype = "dashed", 
    size = .25
  ) +
  geom_quasirandom(
    aes(
      estimate, name, fill = value, group = value
    ),
    shape = 21,
    bandwidth = .0005,
    size = .65,
    groupOnX = F,
    dodge.width = .6,
    data = t1
  ) +
  geom_quasirandom(
    aes(
      estimate, name, color = value, group = value
    ),
    bandwidth = .0005,
    size = .4,
    groupOnX = F,
    dodge.width = .6,
    data = t1
  ) +
  geom_segment(
    aes(
      x = xlo, xend = xhi,
      y = name %>% as.numeric %>% add(yint) %>% add(.5),
      yend = name %>% as.numeric %>% add(yint) %>% add(.5)
      ),
    data = t2,
    size = .25,
    linetype = "dotted"
    ) +
  geom_segment(
      aes(
        x = xlo, xend = xlo,
        y = name %>% as.numeric %>% add(yint),
        yend = name %>% as.numeric %>% add(.5) %>% add(yint)
      ),
      data = t2,
      size = .25,
      linetype = "dotted"
    ) +
  geom_segment(
    aes(
      x = xhi, xend = xhi,
      y = name %>% as.numeric %>% add(yint),
      yend = name %>% as.numeric %>% add(.5) %>% add(yint)
    ),
    data = t2,
    size = .25,
    linetype = "dotted"
  ) +
  geom_label(
      aes(
        x = mid, label = slab,
        y = name %>%
          as.numeric %>%
          add(.465) %>% 
          add(yint)
        ),
      data = t2,
      fill = "grey98",
      label.size = 0,
      fontface = "bold",
      size = 3,
      label.padding = unit(0.125, "lines")
    ) +
  geom_point(
    aes(
      x = estimate, y = name, fill = value
    ),
    data = t0,
    shape = 21,
    size = 5.5,
    position = position_dodge(.65)
  ) +
  geom_linerange(
    aes(
      xmin = conf.low %>% subtract(.05), xmax = conf.high %>% add(.05), y = name, group = value
    ),
    size = .8,
    color = "black",
    data = t0,
    position = position_dodge(.65)
  ) +
  geom_linerange(
    aes(
      xmin = conf.low, xmax = conf.high, y = name, color = value
    ),
    data = t0,
    position = position_dodge(.65)
  ) +
  geom_point(
    aes(
      x = estimate, y = name, fill = value
    ),
    shape = 21,
    data = t0,  
    size = 5.4,
    position = position_dodge(.65)
  ) +
  geom_text(
    aes(
      estimate, name, label = estimate %>% round(1), group = value
    ),
    size = 1.4,
    color ="black",
    position = position_dodge(.65),
    data = t0
    ) +
  geom_text(
    aes(
      x, y, label = lab
    ),
    data = tribble(
      ~x,   ~y, ~lab,
      -6.6, 5.8, "Low on\nscale",
      -13.3, 5.8, "High on\nscale"
    ) %>%
      mutate(
        cfac = t0$cfac %>%
          levels %>%
          extract2(2) %>%
          factor(
            t0$cfac %>%
              levels
          ),
        rfac = "Personality\ntraits" %>%
          factor(
            t0$rfac %>%
              factor %>%
              levels
          )
      ),
    size = 2.5,
    lineheight = .7,
    fontface = 'italic'
  ) +
  facet_grid(
    rfac ~ cfac, 
    scales = "free", 
    space = "free"
  ) +
  scale_fill_grey(
    start = .6,
    end = .99
  ) +
  scale_color_grey(
    start = .6,
    end = .99
  ) +
  scale_y_discrete(
    expand = expansion(add = c(.75, 1.2)),
    breaks = t0$name %>% 
      levels,
    labels = t0$name %>% 
      levels %>% 
      str_remove("Personality - ")
  ) +
  scale_x_continuous(
    breaks = seq(-30, 30, 10)
  ) +
  labs(
    x = "", 
    y = ""
  ) 
  